#ifndef _CONNECTION_H
#define _CONNECTION_H

#include <stdio.h>  
#include <stdlib.h> 
#include <unistd.h> 
#include <malloc.h>  
#include <ev.h>  
#include <netinet/in.h>  
#include <arpa/inet.h>  
#include <sys/socket.h>  
#include <sys/types.h>  
#include <string.h>
#include "ev++.h"
#include <string>
#include "Callback.hpp"

class accept_callback;
class Server;

class Connection {
	friend class client_callback;
	friend class accept_callback;
private:
	Server *server;
	int client_fd;                               //客户端连接对应的fd
	char *ip_addr;                               //客户端的ip地址         
	ev::io w_client;                             //客户端的读写监视器                              
	struct ev_loop *client_loop;                 //客户端对应的事件循环，指向服务器的事件循环
	client_callback *cl_cb;                      //客户端对应的事件回调，指向服务器的事件回调
	
	Connection(const Connection &);                      //该类不允许复制
	const Connection & operator= (const Connection &);   //该类不允许赋值

public:
	void start();
	Connection(int fd, const char *addr, struct ev_loop *loop);
	~Connection();
};
#endif

